package com.dcc.xiangche.support;

import cn.hutool.core.util.BooleanUtil;
import com.sun.org.apache.xpath.internal.functions.WrongNumberArgsException;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class MainHandler implements CommandLineRunner {
    @Resource
    private WSXCHandler handler;
    @Override
    public void run(String... args) throws Exception {
        if(args.length<2){
            throw new WrongNumberArgsException("至少需要两个参数，第一个参数为主目录; 第二个参数为json文件名称");
        }
        boolean overwrite=false;
        if(args.length==3){
            try {
                overwrite = BooleanUtil.toBoolean(args[2]);
            }catch (Exception e){}
        }
        handler.process(args[0],args[1],overwrite);
    }
}
